package com.zp.qualitypractice.list.footer;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zp.qualitypractice.R;
import com.zp.qualitypractice.list.CustomLoadingView;

/**
 * Created by izp on 2017/4/24.
 */

public class FooterView extends LinearLayout {
    private CustomLoadingView mLoadingView;
    private TextView mFooterHint;

    /**
     * 加载中
     */
    public final static int STATE_LOADING = 0;
    /**
     * 加载完成
     */
    public final static int STATE_COMPLETE = 1;
    /**
     * 正常状态
     */
    public final static int STATE_NO_MORE = 2;

    public FooterView(Context context) {
        super(context);
    }

    public FooterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public FooterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public FooterView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    private void init(Context context){
        setGravity(Gravity.CENTER);
        setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        View contentView = View.inflate(context, R.layout.item_bubble_loading_footer,null);
        mLoadingView = (CustomLoadingView) contentView.findViewById(R.id.bubble_loading_footer);
        mFooterHint = (TextView) contentView.findViewById(R.id.loading_hint);
        addView(contentView);
    }

    public void setState(int state){
        switch (state){
            case STATE_LOADING:
                mLoadingView.setVisibility(View.VISIBLE);
                mFooterHint.setText("加载中...");
                this.setVisibility(View.VISIBLE);
                break;
            case STATE_COMPLETE:
                mFooterHint.setText("加载中...");
                this.setVisibility(View.GONE);
                break;
            case STATE_NO_MORE:
                mFooterHint.setText("没有更多了..");
                mLoadingView.setVisibility(View.GONE);
                this.setVisibility(View.VISIBLE);
                break;
        }
    }
}
